/**
 * TypeSystem implements all type checking.
 * This version is just a stub and its your job to complete it!! 
 * @author MLB
 *
 */
public class TypeSystem {
    // constant types are created as static attributes of the TypeSystem
	static final public 
		Type T_integer = new Type("INTEGER", 4),
		T_c_integer = new Type("C_INTEGER", 4), 
		T_c_text = new Type("TEXT",-1), 
		T_label = new Type("LABEL", -1), 
		T_pointer = new Type("POINTER", 4),
		T_error = new Type("ERROR", -1),
		T_void = new Type("VOID", 0);
    // get functions for constant types
	static public Type TypeInteger() {
		return T_integer;
	}

	static public Type TypeVoid() {
		return T_void;
	}

	static public Type TypePointer() {
		return T_pointer;
	}

	static public Type TypeConstInteger() {
		return T_c_integer;
	}

	static public Type TypeLabel() {
		return T_label;
	}


    // an Example
	/**
	 * Type checking for a binary operation - in VSL+: integer operations only!
	 */

	public static Type CheckBinOp(Type t1, Type t2) {
		if (t1 == T_integer && t1 == T_integer)
			return T_integer;
		else
			return T_error;
	}
	
	public static Type CheckInteger(Type t){
		if(t == T_integer)
			return T_integer;
		else
			return T_error;
	}

	public static void error(String s1, String s2) {
		System.out.println("TypeSystem: " + s1 + s2);
	}

	public static Boolean Check_dec_ident(String nom, SymbolTable ts){
		Operand3a res = ts.Lookup(nom);
		if( res != null){
			return true;
		}
		return false;
	}
	
}// end TypeSystem
